package com.shanzmoo.pay.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * @author dingmeng
 * @title: ApiUtil
 * @projectName jyf-mall-server
 * @description: 签名生成工具类
 * @date 2021/4/417:39
 */
public class ApiUtil {

    public static <T> JSONObject convertRequest(T t, String key, String keyname) {
        JSONObject obj = JSON.parseObject(JSON.toJSONString(t));
        String key_sign = SignBeanUtil.FilterNullSign(t, keyname, key, "key_sign", "utf-8");
        obj.put("key_sign", key_sign);
        return obj;
    }

    /**
     *
     * @param body   所有参数
     * @param t      参与签名的参数
     * @param key    令牌值
     * @param keyname 令牌名称
     * @param <T>
     * @return
     */
    public static <T> JSONObject convertMerchantRequest(T body,T t, String key, String keyname) {
        JSONObject obj = JSON.parseObject(JSON.toJSONString(body));
        String key_sign = SignBeanUtil.FilterNullSign(t, keyname, key, "key_sign", "utf-8");
        obj.put("key_sign", key_sign);
        return obj;
    }

}
